/**
 *
 * @param table {Table}
 * @param auth {boolean} 接口是否需要鉴权
 * @param uninstall {boolean} 是否在生成代码时注释该方法，用于备用
 * @returns {string}
 */
const page = (table, auth = false, uninstall = false) => {
  const {
    comment,
    date,
    author,
    names: {TabName}
  } = table
  const ordered = table.incrementAndGetOrdered()
  return `// <-
    @GetMapping("/page/{number}/{limit}")
    //@PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_ADMIN_TEST', '{}_load')")
    @ApiOperation(value = "${ordered}.分页查询${comment}", tags = {""})
    @ApiOperationSupport(
            order = ${ordered},
            author = "${author}",
            includeParameters = {"number", "limit", "orderBy", "${table.getQueryIncludeColumnNames()}"}
    )
    @ResponseBody
    public Result<${TabName}> page(
            @ApiIgnore @AuthenticationPrincipal final IUser user, 
            @ApiParam(required = true, value = "页码", example = "1") @PathVariable final int number,
            @ApiParam(required = true, value = "每页条数，最大值1000", example = "10") @PathVariable final int limit,
            final ${TabName} condition) {
        return new Result<${TabName}>().execute(result -> { // Controller 方法逻辑写在这里
            result.setSuccess(service.page(condition, Page.of(number, limit)));
        });
    }
`.split('\n')
    .map(row => (uninstall ? '//' : '') + row)
    .join('\n')
}
export const pageOpenInstall = table => page(table)
export const pageOpenUninstall = table => page(table, false, true)

export const pageAuthInstall = table => page(table, true, false)
export const pageAuthUninstall = table => page(table, true, true)
